package com.youlu.campus.admin.commission;


import com.youlu.campus.admin.auth.entity.SystemRole;
import com.youlu.campus.admin.auth.service.RoleService;
import com.youlu.campus.admin.utils.AuthUtils;
import com.youlu.campus.entity.commission.dto.UserParticipateChannelQueryDTO;
import com.youlu.campus.service.commission.UserParticipateDistributorChannelInfoService;
import com.yuelin.infrastructure.quantum.common.QResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
public class UserParticipateChannelController {

    @Autowired
    private UserParticipateDistributorChannelInfoService userParticipateDistributorChannelInfoService;

    @Autowired
    private RoleService roleService;

    @PostMapping("/distributor/channel/user/list")
    public QResult list (@RequestBody UserParticipateChannelQueryDTO dto){
        String userId = AuthUtils.getUserId();
        List<SystemRole> roleList = roleService.findAllByUserId(userId);
        long count = roleList.stream().filter(role -> "渠道分销".equals(role.getName())).count();
        if (count > 0) {
            dto.setDistributorChannelRole(Boolean.TRUE);
            dto.setDistributorChannelUserId(userId);
        }
        log.info("渠道报名用户名单 userId:{},是否是渠道分销角色:{}",userId,count);
        return QResult.success(userParticipateDistributorChannelInfoService.list(dto));
    }


}
